package com.tangyee.home_blood_center.activities;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;

import com.tangyee.home_blood_center.db.BSRecordHolder;
import com.tangyee.home_blood_center.fragments.AddBloodSugarRecordFragment;
import com.tangyee.home_blood_center.utils.HandleBackUtil;
import com.tangyee.R;
import com.tangyee.home_blood_center.db.BSRecordHolder;
import com.tangyee.home_blood_center.fragments.AddBloodSugarRecordFragment;
import com.tangyee.home_blood_center.utils.HandleBackUtil;
import java.util.Date;
//AddBloodSugarRecordFragmentne.wInstance(BSRecordHolder.get(getApplicationContext()).getLastBSRecord().getDate().getTime() * 10 + new Date().getHours()/3 + 1);
public class AddBloodSugarActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment);

        //禁止横屏，不禁止太多坑了
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

        // 耗时操作都在这里
        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragment_container);
        if (fragment == null) {
                fragment = AddBloodSugarRecordFragment.newInstance(BSRecordHolder.get(getApplicationContext()).getLastBSRecord().getDate().getTime() * 10 + new Date().getHours()/3 + 1);
                fm.beginTransaction().add(R.id.fragment_container, fragment).commit();
        }

    }

    /**
     * 重写返回键点击方法，让其执行自定义的方法（将返回事件分发给所有继承了BaseFragment的fragment）
     */
    @Override
    public void onBackPressed() {
        if (!HandleBackUtil.handleBackPress(this)) {
            super.onBackPressed();
        }
    }

}
